#!/usr/bin/env python
# --*-- conding:utf-8 --*--
# @Time : 2024/1/28
# @Author : liangpp
# @Email : mobaicloud@163.com
# @Software : PyCharm


from carlargescreen.models import CarInfo


def get_centerright2():
    allcars = CarInfo.objects.all()
    # 价格分布图，取最低配价格来定
    price_list = []
    for car in allcars:
        price_list.append(car.price)
    min_price_list = []
    for price in price_list:
        if price == "0-0":
            continue
        min_price = price.split("-")[0]
        min_price_list.append(min_price)
    price_dict = {
        "0-10万元": 0,
        "10-20万元": 0,
        "20-30万元": 0,
        "30-50万元": 0,
        "50万元以上": 0,
    }
    for price in min_price_list:
        if float(price) >= 0 and float(price) < 10:
            price_dict["0-10万元"] += 1
        elif float(price) >= 10 and float(price) < 20:
            price_dict["10-20万元"] += 1
        elif float(price) >= 20 and float(price) < 30:
            price_dict["20-30万元"] += 1
        elif float(price) >= 30 and float(price) < 50:
            price_dict["30-50万元"] += 1
        else:
            price_dict["50万元以上"] += 1
    format_list = []
    for k, v in price_dict.items():
        format_dict = {
            "name": k,
            "value": v
        }
        format_list.append(format_dict)
    # print(format_list)
    return format_list